home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / call_infix_eq_neq.e < prev    next >
Text File  |  1998-01-16  |  8KB  |  328 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. deferred class CALL_INFIX_EQ_NEQ
  17.    --
  18.    -- Root for "=" and "/=".
  19.    --
  20.  
  21. inherit 
  22.    CALL_INFIX
  23.       undefine compile_to_c
  24.       redefine afd_check, use_current, to_runnable, finalize
  25.       end;
  26.  
  27. feature 
  28.  
  29.    precedence: INTEGER is 6;
  30.    
  31.    frozen use_current: BOOLEAN is
  32.       do
  33.      Result := target.use_current or else arg1.use_current;
  34.       end;
  35.  
  36.    frozen afd_check is
  37.       do
  38.      target.afd_check;
  39.      arg1.afd_check;
  40.       end;
  41.  
  42.    frozen to_runnable(ct: TYPE): like Current is
  43.       do
  44.      if current_type = Void then
  45.         to_runnable_equal_not_equal(ct);
  46.         result_type := type_boolean;
  47.         if nb_errors = 0 then
  48.            Result := Current;
  49.         end;
  50.      else
  51.         !!Result.make(target,feature_name.start_position,arg1);
  52.         Result := Result.to_runnable(ct);
  53.      end;
  54.       end;
  55.    
  56.    isa_dca_inline_argument: INTEGER is
  57.      -- *** FAIRE ***
  58.       do
  59.       end;
  60.  
  61.    dca_inline_argument(formal_arg_type: TYPE) is
  62.      -- *** FAIRE ***
  63.       do
  64.       end;
  65.  
  66. feature {RUN_FEATURE_4}
  67.  
  68.    frozen dca_inline(formal_arg_type: TYPE) is
  69.       do
  70.      cpp.put_character('(');
  71.      cpp.put_target_as_value;
  72.      cpp.put_character(')');
  73.      if operator.first = '=' then
  74.         cpp.put_string(fz_c_eq);
  75.      else
  76.         cpp.put_string(fz_c_neq);
  77.      end;
  78.      cpp.put_character('(');
  79.      arg1.dca_inline_argument(formal_arg_type);
  80.      cpp.put_character(')');
  81.       end;
  82.  
  83. feature {RUN_FEATURE_3,RUN_FEATURE_4}
  84.  
  85.    finalize is
  86.       do
  87.       end;
  88.  
  89. feature {NONE}
  90.  
  91.    frozen to_runnable_equal_not_equal(ct: TYPE) is
  92.      -- Because there is no feature definition for "=" and "/=".
  93.       require
  94.      ct /= Void;
  95.      current_type = Void;
  96.       local
  97.      t: like target;
  98.      a: like arguments;
  99.      tt, at: TYPE;
  100.       do
  101.      current_type := ct;
  102.      t := target.to_runnable(ct);
  103.      if t = Void then
  104.         error(target.start_position,"Bad target.");
  105.      else
  106.         target := t;
  107.      end;
  108.      a := arguments.to_runnable(ct);
  109.      if a /= Void then
  110.         arguments := a;
  111.      end;
  112.      if nb_errors = 0 then
  113.         tt := target.result_type.run_type;
  114.         at := arg1.result_type.run_type;
  115.         if tt.is_none then
  116.            if at.is_expanded then
  117.           at.used_as_reference;
  118.            end;
  119.         elseif at.is_none then
  120.            if tt.is_expanded then
  121.           tt.used_as_reference;
  122.            end;
  123.         elseif tt.is_reference then
  124.            if at.is_reference then
  125.           if tt.is_a(at) then
  126.           else
  127.              eh.cancel;
  128.              if at.is_a(tt) then
  129.              else
  130.             error_comparison("Reference/Reference");
  131.              end;
  132.           end;
  133.            elseif not at.is_a(tt) then
  134.           error_comparison("Reference/Expanded");
  135.            else
  136.           at.used_as_reference;
  137.            end;
  138.         else
  139.            if at.is_expanded then
  140.           if at.is_basic_eiffel_expanded then
  141.              if tt.is_a(at) then
  142.              else
  143.             eh.cancel;
  144.             if at.is_a(tt) then
  145.             else
  146.                error_comparison("Expanded/Expanded");
  147.             end;
  148.              end;
  149.           elseif tt.is_bit then
  150.              bit_limitation(tt,at);
  151.           elseif not at.is_a(tt) then
  152.              error_comparison("Expanded/Expanded");
  153.           end;
  154.            elseif not tt.is_a(at) then
  155.           error_comparison("Expanded/Reference");
  156.            else
  157.           tt.used_as_reference;
  158.            end;
  159.         end;
  160.      end;
  161.       ensure
  162.      current_type = ct;
  163.       end;
  164.  
  165.    error_comparison(str: STRING) is
  166.       do
  167.      eh.add_position(feature_name.start_position);
  168.      eh.append(" Comparison ");
  169.      eh.append(str); 
  170.      eh.append(" Not Valid. Context of Types interpretation is ");
  171.      eh.add_type(current_type,fz_dot);
  172.      eh.print_as_error;
  173.       end;
  174.  
  175.    bit_limitation(t1, t2: TYPE) is
  176.       require
  177.      t1.is_bit;
  178.      t2.is_bit
  179.       local
  180.      b1, b2: TYPE_BIT;
  181.       do
  182.      b1 ?= t1;
  183.      b2 ?= t2;
  184.      if b1.nb /= b2.nb then
  185.         eh.add_position(feature_name.start_position);
  186.         eh.append("Comparison between ");
  187.         eh.add_type(b1," and ");
  188.         eh.add_type(b2,
  189.             " is not yet implemented (you can work arround doing an %
  190.         %assignment in a local variable).");
  191.         eh.print_as_fatal_error;
  192.      end;
  193.       end;
  194.  
  195. feature {NONE}
  196.  
  197.    is_manifest_array(e: EXPRESSION): BOOLEAN is
  198.       local
  199.      ma: MANIFEST_ARRAY;
  200.       do
  201.      ma ?= e;
  202.      Result := ma /= Void;
  203.       end;
  204.  
  205. feature {NONE} -- Low level comparison tools :
  206.  
  207.    cmp_bit(equal_test: BOOLEAN; t: TYPE) is
  208.       require
  209.      t.is_bit
  210.       local
  211.      tb: TYPE_BIT;
  212.       do
  213.      tb ?= t;
  214.      if tb.is_c_unsigned_ptr then
  215.         if equal_test then
  216.            cpp.put_character('!');
  217.         end;
  218.         cpp.put_string("memcmp((");
  219.         target.mapping_c_arg(t);
  220.         cpp.put_string("),(");
  221.         arg1.mapping_c_arg(t);
  222.         cpp.put_string("),");
  223.         cpp.put_integer(tb.space_for_variable);
  224.         cpp.put_string(")");
  225.      else
  226.         cpp.put_character('(');
  227.         target.compile_to_c;
  228.         cpp.put_character(')');
  229.         if equal_test then
  230.            cpp.put_string(fz_c_eq);
  231.         else
  232.            cpp.put_string(fz_c_neq);
  233.         end;
  234.         cpp.put_character('(');
  235.         arg1.compile_to_c;
  236.         cpp.put_character(')');
  237.      end;
  238.       end;
  239.  
  240.    cmp_user_expanded(equal_test: BOOLEAN; t: TYPE) is
  241.       require
  242.      t.is_user_expanded
  243.       local
  244.      mem_id: INTEGER;
  245.       do
  246.      if t.is_dummy_expanded then
  247.         cpp.put_character('(');
  248.         target.compile_to_c;
  249.         cpp.put_character(',');
  250.         arg1.compile_to_c;
  251.         cpp.put_character(',');
  252.         if equal_test then
  253.            cpp.put_character('1');
  254.         else
  255.            cpp.put_character('0');
  256.         end;
  257.         cpp.put_character(')');
  258.      else
  259.         mem_id := t.id;
  260.         if equal_test then
  261.            cpp.put_character('!');
  262.         end;
  263.         cpp.put_string(fz_se_cmpt);
  264.         cpp.put_integer(mem_id);
  265.         cpp.put_string("((");
  266.         target.compile_to_c;
  267.         cpp.put_string("),(");
  268.         arg1.compile_to_c;
  269.         cpp.put_string("))");
  270.      end;
  271.       end;
  272.  
  273.    cmp_basic_eiffel_expanded(equal_test: BOOLEAN; t1, t2: TYPE) is
  274.       require
  275.      t1.is_basic_eiffel_expanded;
  276.      t2.is_basic_eiffel_expanded
  277.       local
  278.      flag: BOOLEAN;
  279.       do
  280.      flag := t1.is_real or else t2.is_real;
  281.      if flag then
  282.         cpp.put_string(fz_cast_float);
  283.      end;
  284.      cpp.put_character('(');
  285.      target.compile_to_c;
  286.      if flag then
  287.         cpp.put_string(fz_13);
  288.      end;
  289.      cpp.put_character(')');
  290.      if equal_test then
  291.         cpp.put_string(fz_c_eq);
  292.      else
  293.         cpp.put_string(fz_c_neq);
  294.      end;
  295.      cpp.put_character('(');
  296.      if flag then
  297.         cpp.put_string(fz_cast_float);
  298.      end;
  299.      arg1.compile_to_c;
  300.      cpp.put_character(')');
  301.      if flag then
  302.         cpp.put_string(fz_13);
  303.      end;
  304.       end;
  305.  
  306.    cmp_basic_ref(equal_test: BOOLEAN) is
  307.       do
  308.      cpp.put_character('(');
  309.      target.compile_to_c;
  310.      cpp.put_character(')');
  311.      if equal_test then
  312.         cpp.put_string(fz_c_eq);
  313.      else
  314.         cpp.put_string(fz_c_neq);
  315.      end;
  316.      cpp.put_character('(');
  317.      cpp.put_string(fz_cast_void_star);
  318.      cpp.put_character('(');
  319.      arg1.compile_to_c;
  320.      cpp.put_character(')');
  321.      cpp.put_character(')');
  322.       end;
  323.  
  324.    fz_cast_float: STRING is "((float)(";
  325.  
  326. end -- CALL_INFIX_EQ_NEQ
  327.  
  328.